using ASP;
using HoWave.Common;
using HoWave.Web;
using HoWave.Web.Shop.Member;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
public class Credit_Identify_user : Member, IRequiresSessionState
{
	public string Action = "";
	protected ScriptManager ScriptManager1;
	protected UserControls_cmpy_Top Top1;
	protected Literal UserName;
	protected RadioButtonList RadioU_UserSex;
	protected TextBox TxtU_TrueName;
	protected RequiredFieldValidator RequiredFieldValidator1;
	protected Literal Email;
	protected TextBox Txt_HomePhone;
	protected RegularExpressionValidator rfv5;
	protected TextBox TxtU_MobilePhone;
	protected RequiredFieldValidator rfv3;
	protected RegularExpressionValidator rex1;
	protected TextBox TxtU_IDCard;
	protected RequiredFieldValidator rfv2;
	protected RegularExpressionValidator RegularExpressionValidator2;
	protected FileUpload fuIDCardImg;
	protected HiddenField hfIDCardImg;
	protected HtmlImage IDCardImg;
	protected FileUpload fuIDCardImgBack;
	protected HiddenField hfIDCardImgBack;
	protected HtmlImage IDCardImgBack;
	protected Label err_tips;
	protected HtmlInputButton goback;
	protected Button SaveInfo;
	protected UserControls_CMYP_Foot Foot1;
	protected HtmlForm form1;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Init(object sender, EventArgs e)
	{
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		this.UserName.Text = base.user.UserName;
		this.Action = Fetch.Get("action");
		if (this.conn.ExecuteCount("Select Count(IdentifyID) From [HLShop_Application] Where IdentifyType=1 and UserID=" + base.user.UserID) > 0)
		{
			this.Action = "Modify";
		}
		if (!base.IsPostBack)
		{
			this.fuIDCardImg.Attributes.Add("onchange", "return ShowUpdatePic(this);");
			this.fuIDCardImgBack.Attributes.Add("onchange", "return ShowUpdatePicBack(this);");
			if (this.conn.ExecuteCount("Select Count(UserInfoID) From [HL_UserInfo] Where UserID=" + base.user.UserID) <= 0)
			{
				this.WriteErrMsg("", Language.Get("PassPort/NotUserInfo"), "/Member/Shop_UserInfoList.aspx");
			}
			if (this.Action == "Modify")
			{
				this.InitUserMifiy();
			}
			else
			{
				this.InitUserInfoPage();
			}
		}
	}
	protected void InitUserInfoPage()
	{
		int userID = base.user.UserID;
		this.TxtU_TrueName.Text = base.user.UserInforRes["TrueName"].ToString();
		this.TxtU_MobilePhone.Text = base.user.UserInforRes["MobilePhone"].ToString();
		this.TxtU_IDCard.Text = base.user.UserInforRes["IDCard"].ToString();
		this.Txt_HomePhone.Text = base.user.UserInforRes["HomePhone"].ToString();
		this.Email.Text = base.user.UserEmail;
		string text = base.user.UserInforRes["Sex"].ToString();
		if (text.Trim().ToLower() == "false" || text.Trim() == "0")
		{
			this.RadioU_UserSex.Items[0].Selected = true;
		}
		else
		{
			this.RadioU_UserSex.Items[1].Selected = true;
		}
	}
	protected void InitUserMifiy()
	{
		int userID = base.user.UserID;
		Shop_Application shop_Application = new Shop_Application(this.conn);
		DataTable applicationByUserIDType = shop_Application.GetApplicationByUserIDType(userID, 1);
		if (applicationByUserIDType != null && applicationByUserIDType.Rows.Count >= 1)
		{
			string[] contentArray = applicationByUserIDType.Rows[0]["IdentifyDetail"].ToString().Split(new char[]
			{
				'$'
			});
			string a = applicationByUserIDType.Rows[0]["Status"].ToString();
			this.UserName.Text = applicationByUserIDType.Rows[0]["UserName"].ToString();
			this.TxtU_TrueName.Text = base.user.UserInforRes["TrueName"].ToString();
			this.TxtU_IDCard.Text = base.user.UserInforRes["IDCard"].ToString();
			this.Txt_HomePhone.Text = base.user.UserInforRes["HomePhone"].ToString();
			this.TxtU_MobilePhone.Text = base.user.UserInforRes["MobilePhone"].ToString();
			this.Email.Text = base.user.UserEmail;
			string text = base.user.UserInforRes["Sex"].ToString();
			if (text.Trim().ToLower() == "false" || text.Trim() == "0")
			{
				this.RadioU_UserSex.Items[0].Selected = true;
			}
			else
			{
				this.RadioU_UserSex.Items[1].Selected = true;
			}
			string text2 = Shop_Application.GetContentByName("IDCardUploadUrl", contentArray);
			if (string.IsNullOrEmpty(text2) || text2 == "")
			{
				text2 = "/images/show_nopic.gif";
			}
			else
			{
				text2 = text2.Replace('\\', '/');
			}
			this.hfIDCardImg.Value = text2;
			this.IDCardImg.Src = ".." + text2;
			string text3 = Shop_Application.GetContentByName("IDCardUploadUrlBack", contentArray);
			if (string.IsNullOrEmpty(text3) || text3 == "")
			{
				text3 = "/images/show_nopic.gif";
			}
			else
			{
				text3 = text3.Replace('\\', '/');
			}
			this.hfIDCardImgBack.Value = text3;
			this.IDCardImgBack.Src = ".." + text3;
			if (a == "0" || a == "-1")
			{
				this.SaveInfo.Enabled = true;
			}
			else
			{
				this.SaveInfo.Enabled = false;
			}
		}
	}
	protected void SaveInfo_Click(object sender, EventArgs e)
	{
		if (this.Action == "Pass")
		{
			this.WriteErrMsg("", Language.GetMemberMsg("Ventify/NotModify", new string[0]), "/Member/Shop_Identify.aspx");
		}
		if (this.CheckInput())
		{
			int userID = base.user.UserID;
			string userName = base.user.UserName;
			string text = this.UploadPhoto();
			if (text == "")
			{
				text = this.hfIDCardImg.Value;
			}
			string text2 = this.UploadPhotoBack();
			if (text2 == "")
			{
				text2 = this.hfIDCardImgBack.Value;
			}
			string text3 = this.TxtU_MobilePhone.Text;
			string text4 = this.Txt_HomePhone.Text;
			Shop_Application shop_Application = new Shop_Application(this.conn);
			string identifyDetail = shop_Application.AddPersonIdentifyDetail(this.TxtU_TrueName.Text, this.TxtU_IDCard.Text, text, text2, text4, text3);
			int num;
			if (this.RadioU_UserSex.Items[0].Selected)
			{
				num = 0;
			}
			else
			{
				num = 1;
			}
			string text5 = this.Email.Text.Trim().ToString();
			string sqlUser = string.Concat(new object[]
			{
				"Update [HL_User] Set [Sex]=",
				num,
				",[Email]='",
				text5,
				"' Where UserID=",
				userID
			});
			string sqlUserInfo = string.Concat(new object[]
			{
				"Update [HL_UserInfo] Set [TrueName]='",
				this.TxtU_TrueName.Text,
				"',[MobilePhone]='",
				text3,
				"',[HomePhone]='",
				text4,
				"',[IDCard]='",
				this.TxtU_IDCard.Text,
				"',[sex]=",
				num,
				",AuthenticationType=9 Where UserID=",
				userID
			});
			bool flag;
			if (this.Action == "Modify")
			{
				if ((text == "" || text == null) && this.fuIDCardImg.PostedFile.FileName != "")
				{
					this.err_tips.Text = Language.GetMemberMsg("Ventify/UploadFail", new string[0]);
					this.err_tips.CssClass = "tips_wrong";
					return;
				}
				if ((text2 == "" || text2 == null) && this.fuIDCardImgBack.PostedFile.FileName != "")
				{
					this.err_tips.Text = Language.GetMemberMsg("Ventify/UploadFail", new string[0]);
					this.err_tips.CssClass = "tips_wrong";
					return;
				}
				DataTable applicationByUserIDType = shop_Application.GetApplicationByUserIDType(userID, 1);
				if (applicationByUserIDType != null && applicationByUserIDType.Rows.Count >= 1)
				{
					int identifyID = int.Parse(applicationByUserIDType.Rows[0]["IdentifyID"].ToString());
					flag = shop_Application.ModifyApplication(identifyID, userID, userName, 1, identifyDetail, "", text, sqlUser, sqlUserInfo);
				}
				else
				{
					flag = shop_Application.AddApplication(userID, userName, 1, identifyDetail, "", text, sqlUser, sqlUserInfo);
				}
			}
			else
			{
				if (text == "" || text == null)
				{
					this.err_tips.Text = Language.GetMemberMsg("Ventify/UploadFail", new string[0]);
					this.err_tips.CssClass = "tips_wrong";
					return;
				}
				flag = shop_Application.AddApplication(userID, userName, 1, identifyDetail, "", text, sqlUser, sqlUserInfo);
			}
			if (flag)
			{
				this.WriteSuccessMsg("", Language.GetMemberMsg("Ventify/IDVentifing", new string[0]), "/Member/Index.aspx?mainurl=Shop_Identify.aspx");
			}
			else
			{
				this.err_tips.Text = Language.Get("Common/Fail", "");
				this.err_tips.CssClass = "tips_wrong";
			}
		}
		else
		{
			this.err_tips.Text = Language.GetMemberMsg("Ventify/LostParam", new string[0]);
			this.err_tips.CssClass = "tips_wrong";
		}
	}
	protected bool CheckInput()
	{
		return (!(this.TxtU_TrueName.Text == "") && !(this.TxtU_IDCard.Text == "") && !(this.fuIDCardImg.FileName == "") && !(this.fuIDCardImgBack.FileName == "")) || (this.Action == "Modify" && (this.fuIDCardImg.FileName == "" || !(this.fuIDCardImgBack.FileName == "") || true));
	}
	protected string UploadPhotoBack()
	{
		int contentLength = this.fuIDCardImgBack.PostedFile.ContentLength;
		string result;
		if (contentLength > 120000)
		{
			this.WriteErrMsg("", Language.GetMemberMsg("Ventify/UploadTooBig", new string[]
			{
				"120K"
			}), "");
		}
		else
		{
			if (contentLength <= 0 || this.fuIDCardImgBack.PostedFile.FileName == "")
			{
				result = "";
				return result;
			}
		}
		string text = this.fuIDCardImgBack.PostedFile.FileName;
		text = text.Substring(text.LastIndexOf("."));
		if (text.ToUpper() != ".JPG" && text.ToUpper() != ".GIF" && text.ToUpper() != ".PNG")
		{
			this.WriteErrMsg("", "身份证背面图片格式不正确！(图片格式为JPG、GIF、PNG)", "");
		}
		text = string.Concat(new object[]
		{
			"User_",
			base.user.UserID,
			"back",
			text
		});
		string str = "\\UploadFile\\IDCardPic\\";
		UpLoadFile upLoadFile = new UpLoadFile();
		upLoadFile.Suffix = "gif|jpg|jpeg|bmp";
		upLoadFile.myfile = this.fuIDCardImgBack;
		bool flag = upLoadFile.UpLoad(str + text);
		if (flag)
		{
			result = str + text;
		}
		else
		{
			this.WriteErrMsg("", Language.Get("Common/Fail", upLoadFile.ErrString), "");
			result = "";
		}
		return result;
	}
	protected string UploadPhoto()
	{
		int contentLength = this.fuIDCardImg.PostedFile.ContentLength;
		string result;
		if (contentLength > 120000)
		{
			this.WriteErrMsg("", Language.GetMemberMsg("Ventify/UploadTooBig", new string[]
			{
				"120K"
			}), "");
		}
		else
		{
			if (contentLength <= 0 || this.fuIDCardImg.PostedFile.FileName == "")
			{
				result = "";
				return result;
			}
		}
		string text = this.fuIDCardImg.PostedFile.FileName;
		text = text.Substring(text.LastIndexOf("."));
		if (text.ToUpper() != ".JPG" && text.ToUpper() != ".GIF" && text.ToUpper() != ".PNG")
		{
			this.WriteErrMsg("", "身份证正面图片格式不正确！(图片格式为JPG、GIF、PNG)", "");
		}
		text = "User_" + base.user.UserID + text;
		string str = "\\UploadFile\\IDCardPic\\";
		UpLoadFile upLoadFile = new UpLoadFile();
		upLoadFile.Suffix = "gif|jpg|jpeg|bmp";
		upLoadFile.myfile = this.fuIDCardImg;
		bool flag = upLoadFile.UpLoad(str + text);
		if (flag)
		{
			string text2 = str + text;
			result = text2;
		}
		else
		{
			this.WriteErrMsg("", Language.Get("Common/Fail", upLoadFile.ErrString), "");
			result = "";
		}
		return result;
	}
}
